My Programming Lab PYTHON help please Suppose there is a cla

My Programming Lab (PYTHON) help please...

Suppose there is a class Roster. Roster has one variable , roster, which is a List of tuples containing the names of students and their number grades--for example, [(\'Richard\', 90), (\'Bella\', 67), (\'Christine\', 85), (\'Francine\', 97)].

Roster has a function findValedictorian that returns the name of the student with the highest grade. Find the valedictorian of the Roster object englishClass and store it in the variable  valedictorian.

Solution

Please find the required program along with its output. Please see the comments against each line to understand the step.

class Roster:
   roster = []

   def __init__(self, rostr): #constructor using rostr
       self.roster = rostr

   def findValedictorian (self): #returns the valedictorian
       max = 0       #initialize max as 0 to store max mark, and also stdnt vairable to store student name
       stdnt = \"\"
       for student, mark in self.roster:   #iterate over all tuples
           if(mark>max):   #if current student\'s mark is > max mark, then save the mark as max and student\'s name in stdnt
               max = mark
               stdnt = student
       return stdnt   #return the student corresponding to the max mark
      
      
englishClass = Roster([(\'Richard\', 90), (\'Bella\', 67), (\'Christine\', 85), (\'Francine\', 97)])   #create a englishClass Roster class object
valedictorian = englishClass.findValedictorian()   #call the method findValedictorian to find the valedictorian

print(\"valedictorian : \",valedictorian)   #print valedictorian

--------------------------------------------

OUTPUT:

My Programming Lab (PYTHON) help please... Suppose there is a class Roster. Roster has one variable , roster, which is a List of tuples containing the names of

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site